import Vue from 'vue'
import Vuex from 'vuex'
import { LOGIN } from './mutation-types'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: {
    user: {
      name: '',
      role: ''
    }
  },
  getters: {
    user(state){
      return state.user
    }
  },
  mutations: {
    [LOGIN](state, payload) {
      state.user.name = payload.name
      state.user.role = payload.role
    }
  },
  actions: {
    login({commit}, payload){
      commit(LOGIN, payload)
    }
  }
})

export default store
